//
//  SystemMessageCell.m
//  CYWFrame
//
//  Created by Macx on 2017/9/28.
//  Copyright © 2017年 Macx. All rights reserved.
//

#import "SystemMessageCell.h"

#import "NotificationModel.h"

@implementation SystemMessageCell {
    UIImage *_img;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    self.contentBgView.backgroundColor = kClearColor;
    
    self.date.font = kUHSystemFontWithSize(10);
    self.date.frame = CGRectMake(0, 10, SCREEN_WIDTH, [LZCTools textSizeWithText:@"x" font:kUHSystemFontWithSize(12)].height);
    
    self.headPic.frame = CGRectMake(10, self.date.y+self.date.height+10, SW(10), SW(10));
    self.headPic.layer.cornerRadius = self.headPic.height/2;
    self.headPic.layer.masksToBounds = YES;
    
    self.content.font = kUHSystemFontWithSize(14);
    CGFloat picX = self.headPic.x+self.headPic.width+5;
    
    self.contentBgView.frame = CGRectMake(picX, self.headPic.y, SCREEN_WIDTH-picX-self.headPic.width, 0);
//    self.contentBgView.image = IMAGE(@"chat_box");
    _img = [UIImage imageNamed:@"chat_box"];
//    _img = IMAGE(@"chat_box");

}

- (void)setModel:(NotificationModel *)model {
    if (_model != model) {
        _model = model;
        
        self.date.text = model.human_time;
        
        self.content.text = model.body;
        
        // 布局
        CGSize size1 = [LZCTools textSizeWithText:self.content.text font:self.content.font];
        
        CGSize titleSize = [self.content.text sizeWithFont:self.content.font constrainedToSize:CGSizeMake(self.contentBgView.width-20, size1.height*10) lineBreakMode:NSLineBreakByWordWrapping];
        
        CGFloat picX = self.headPic.x+self.headPic.width+5;
        
        self.content.frame = CGRectMake(picX+10, self.headPic.y+5, titleSize.width, titleSize.height);
        
//        _img = [_img stretchableImageWithLeftCapWidth:floorf(SCREEN_WIDTH-picX-self.headPic.width ) topCapHeight:floorf(self.content.height+10)];
        
        
        UIEdgeInsets edge = UIEdgeInsetsMake(10, 10, 10,10);
        //UIImageResizingModeStretch：拉伸模式，通过拉伸UIEdgeInsets指定的矩形区域来填充图片
       //UIImageResizingModeTile：平铺模式，通过重复显示UIEdgeInsets指定的矩形区域来填充图
       _img= [_img resizableImageWithCapInsets:edge resizingMode:UIImageResizingModeStretch];
        
        self.contentBgView.height = self.content.height+10;
        self.contentBgView.image  = _img;
        
        if (self.contentBgView.height < self.headPic.height) {
            self.height = self.headPic.y+self.headPic.height+10;
        }
        else
            self.height = self.contentBgView.y+self.contentBgView.height+10;
    }
}

- (CGFloat)cellHeight {
    return self.height;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
